package dwz.web.listenerAndInterceptor;

import java.util.List;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import dwz.business.lotto.DaiLiHuiyuanInterface;
import dwz.common.util.MD5Util;
import dwz.persistence.beans.DaiLiHuiyuan;
import dwz.persistence.beans.DaiLiHuiyuanExample;
import dwz.persistence.beans.DaiLiHuiyuanExample.Criteria;
/**
 * 监听系统初始化完毕
 * @author zYppan
 *
 */
@Component
public class SpringContextInitListener implements InitializingBean,ServletContextAware{
	@Autowired
	DaiLiHuiyuanInterface daiLiHuiyuanInterface;
	
	
	@Override
	public void afterPropertiesSet() throws Exception {
		
		System.out.println("是否初始化 呢 ");
		DaiLiHuiyuanExample example = new DaiLiHuiyuanExample();
		Criteria criteria = example.createCriteria();
		criteria = criteria.andYhm_jEqualTo("admin");
		criteria = criteria.andJb_jEqualTo(1);
		List<DaiLiHuiyuan> daiLiHuiyuans = daiLiHuiyuanInterface.selectByExample(example);
		if(daiLiHuiyuans == null || daiLiHuiyuans.size() == 0){
			DaiLiHuiyuan daiLiHuiyuan = new DaiLiHuiyuan();
			daiLiHuiyuan.setYhm_j("admin");
			daiLiHuiyuan.setMm_j(MD5Util.MD5("123456789"));
			daiLiHuiyuan.setJb_j(1);
			daiLiHuiyuan.setSfxgmm_j(0);
			daiLiHuiyuan.setSfty_j(0);
			daiLiHuiyuanInterface.insertSelective(daiLiHuiyuan);
		}
	}

	@Override
	public void setServletContext(ServletContext arg0) {
		
		
	}

}
